<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 作业2，函数封装让用户输入3个数，把和，差，积，商一起返回
    function fn() {
      let arr = []
      for (let i = 1; i <= 3; i++) {
        let num = +prompt(`请输入第${i}个数`)
        // console.log(num);
        arr.push(num)
      }
      const sum = arr.reduce((prev, item) => {
        return prev + item
      }, 0)
      const cha = arr.reduce((prev, item) => {
        return prev - item
      }, 0)
      const ji = arr.reduce((prev, item) => {
        return prev * item
      }, 1)
      const shang = arr.reduce((prev, item) => {
        return prev / item
      }, 1)
      return `三个数和为${sum},差为${cha},积为${ji},商为${shang}`
    }
    console.log(fn());
  </script>
</body>

</html>